package Rt

import (
	"hash"
	"io"
	"crypto/sha1"
	"crypto/md5"
	"crypto/sha256"
	"fmt"
)

var Crypto HxCrypto

func init() {
	Crypto = HxCrypto{}
}

type HxCrypto struct {

}

// md5 hash string
func (this HxCrypto) Md5(str string) string {
	return this.sha(md5.New(), str, "")
}

func (_ HxCrypto) sha(m hash.Hash, str string, salt string) string {
	io.WriteString(m, str)
	if salt != "" {
		io.WriteString(m, salt)
	}
	return fmt.Sprintf("%x", m.Sum(nil))
}

// sha1 hash string
func (this HxCrypto) Sha1(str string) string {
	return this.sha(sha1.New(), str, "")
}

// sha256 hash string
func (this HxCrypto) Sha256(str string) string {
	return this.sha(sha256.New(), str, "")
}

func (this HxCrypto) Md5Salt(str string, salt string) string {
	return this.sha(md5.New(), str, salt)
}

func (this HxCrypto) Sha1Salt(str string, salt string) string {
	return this.sha(sha1.New(), str, salt)
}

func (this HxCrypto) Sha256Salt(str string, salt string) string {
	return this.sha(sha256.New(), str, salt)
}




